<?php

require_once('Model/m_Log.php');

class m_Logger {
	
	private static $my_Logs = array();
		
	public static function setLogMessage($message) {
		$date = new DateTime("now");
		$date = $date->format('Y-m-d H:i:s');
		
		array_push(self::$my_Logs, new m_Log($date, $message, $_SERVER['REMOTE_ADDR'], "Message"));
		
	}
	
	public static function setLogError($message) {
		$date = new DateTime("now");
		$date = $date->format('Y-m-d H:i:s'); 	
	
		$file = 'errors.log';
		$foile = fopen($file, "a");
		
		fwrite($foile, $date . " : " . $message . " (" . $_SERVER['REMOTE_ADDR'] .")\r\n");
		
		fclose($foile);
		
		
		
		$message = "<p style='color:red'>".$message."</style>";
		array_push(self::$my_Logs, new m_Log($date, $message, $_SERVER['REMOTE_ADDR'], "Error"));
		
	}
	
	public static function getLogMessages() {
		$rtn = array();
		
		foreach(self::$my_Logs as $m_Log) {
			if($m_Log->getType() == 'Message') {
				array_push($rtn, $m_Log->getDate(). " : " .$m_Log->getMessage() . " (" . $m_Log->getIP() .")");
			}
		}
		
		return $rtn;
	}
	
	public static function getLogErrors() {
		$errors = array();
		
		$lines = file('errors.log');
		
		foreach ($lines as $line_num => $line) {
 		   $errors[$line_num] =  "#{$line_num} : " . htmlspecialchars($line);
		}

		return $errors;
	}

}